package com.dorado.example.controller;

import com.dorado.kernel.core.exchange.IStatusCode;
import com.dorado.kernel.core.exchange.ResponseEntity;
import com.dorado.kernel.core.exchange.StatusCode;
import com.dorado.kernel.desensitize.sensitive.format.Desensitize;
import com.dorado.kernel.desensitize.sensitive.utils.JSONUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class SensitiveController {
    @Autowired
    private Desensitize desensitize;
    @GetMapping(value = "/dfa/{sensitiveWord}")
    public String desensitizedCustom(@PathVariable("sensitiveWord") String sensitiveWord){
        return desensitize.desensitized(sensitiveWord, "*");
    }

    /**
     * 建议使用工具类
     *
     * @param demoDTO
     * @return
     */
    @GetMapping(value = "sensitivity/jsonUtils", produces = "application/json; charset=utf-8")
    @ResponseBody
    public ResponseEntity  sensitivity(@RequestBody CompVO demoDTO) {
       // String json = buildSensitivitySuccess(demoDTO);
        log.info("脱敏--------Json工具脱敏------数据信息{}", demoDTO);
        //log.info("--------Json----{}", json);
        return StatusCode.OK.build(demoDTO);
    }


    /**
     * 脱敏
     * @param result
     * @return
     */
    public static String buildSensitivitySuccess(Object result){
        return JSONUtils.toJsonStringWithSensitivity(result);
    }




}
